package cn.itcast.chapter01;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class StudentTest {
	
		public static void main(String[] args) {
			java.util.Scanner scanner = new Scanner(System.in);
			java.util.List<Student> list = new LinkedList<Student>();
			while(true){
				System.out.println("-----欢迎来到学生信息管理系统-----");
				System.out.println("1.显示所有学生信息2.添加学生信息3.按照学号查询学生信息4.按照班级名称查询5.修改学生信息6.删除学生信息7.退出");
				System.out.println("请输入您想选择：");
				int a = scanner.nextInt();
				switch(a) {
				case 1:
					//判断是否为空
					if(list.isEmpty()) {
							System.out.println("不好意思现在没有学生信息可查询，请回去录入学生信息");
								break;
					}else {
						////Iterator迭代器
						Iterator<Student> iterator = list.iterator();
						while(iterator.hasNext()) {
								Student next = iterator.next();
								System.out.println(next);
						}
					}
					break;
				case 2:
					for(int i = 0;i < 3;i++) {
							System.out.println("请输入学生学号");
							int id = scanner.nextInt();
							System.out.println("请输入学生姓名");
							String name = scanner.next();
							System.out.println("请输入学生性别");
							String gender = scanner.next();
							System.out.println("请输入学生出生日期");
							String birth = scanner.next();
							System.out.println("请输入学生班级");
							int clase = scanner.nextInt();
							System.out.println("请输入学生的联系方式");
							String phone = scanner.next();
							Student student = new Student(id,name,gender,birth,clase,phone);
							list.add(student);
					}
					System.out.println("录入学生信息成功");
					break;
				case 3:
					//判断是否为空
					if(list.isEmpty()) {
							System.out.println("不好意思现在没有学生信息可查询，请回去录入学生信息");
								break;
					}
					System.out.println("请输入您想查询学生的学号");
					boolean b = true;
					int id1 = scanner.nextInt();
					for(int i = 0;i  < list.size();i++) {
							if(id1 == (list.get(i).getId()));{
									System.out.println("学生信息为："+list.get(i));
									b = false;
							}
					}
					if(b) {
						System.out.println("没有该学号的学生");
					}
					break;
				case 4:
					//判断是否为空
					if(list.isEmpty()) {
						System.out.println("不好意思现在没有学生信息可查询，请回去录入学生信息");
							break;
					}
					System.out.println("请输入您想查询学生的班级");
					boolean c = true;
					int clase1 = scanner.nextInt();
					for(int i = 0;i < list.size();i++) {
							if(clase1 == (list.get(i).setClase())){
									System.out.println("学生的信息为："+list.get(i));
									c = false;
							}
					}
					if(c) {
						System.out.println("没有该班级的学生");
					}
					break;
				case 5:
					//判断是否为空
					if(list.isEmpty()) {
						System.out.println("不好意思现在没有学生信息可查询，请回去录入学生信息");
						break;
					}
					boolean as = true;
					System.out.println("请输入您想修改的学生信息的学号");
					int id2 = scanner.nextInt();
					for(int i = 0;i  < list.size();i++) {
							if(id2 == (list.get(i).getId())) {
								list.remove(i);
								as = false;
								break;
							}else {
								continue;
							}
					}
					if(as) {
						System.out.println("您输入的学号没有");
						break;
					}
					System.out.println("请输入新学生学号");
					int id = scanner.nextInt();
					System.out.println("请输入新学生姓名");
					String name = scanner.next();
					System.out.println("请输入新学生性别");
					String gender = scanner.next();
					System.out.println("请输入新学生出生日期");
					String birth = scanner.next();
					System.out.println("请输入新学生班级");
					int clase = scanner.nextInt();
					System.out.println("请输入新学生的联系方式");
					String phone = scanner.next();
					Student student = new Student(id,name,gender,birth,clase,phone);
					list.add(student);
					break;
				case 6:
					//判断是否为空
					if(list.isEmpty()) {
						System.out.println("不好意思现在没有学生信息可查询，请回去录入学生信息");
						break;
					}
					boolean asd = true;
					System.out.println("请输入您想修改的学生信息的学号");
					int id3 = scanner.nextInt();
					for(int i = 0;i  < list.size();i++) {
						if(id3 == (list.get(i).getId())) {
							list.remove(i);
							System.out.println("删除学生成功");
							asd = false;
							break;
					}else {
						continue;
					}
			}
					if(asd) {
						System.out.println("您输入的学号没有");
						break;
					}
				
				break;
				case 7:
					System.out.println("成功退出");
					break;
			}
			
			}
		}

}
